import axios, { AxiosResponse } from "axios";
interface response {
  code: number;
  data?: any;
}
// let BASE_URL = process.env. == 'development' ?'http://localhost:4000':''
const instance = axios.create({
  baseURL: "http://localhost:4000",
  timeout: 5000,
  headers: {
    "Content-Type": "application/json;charset=utf-8 ",
  },
});
instance.interceptors.request.use((config) => {
  //携带token后端需要配置 这边先注释
  // config.headers = config.headers || {};
  // if (localStorage.getItem("token")) {
  //   config.headers.token = localStorage.getItem("token") || "";
  // }
  return config;
});

instance.interceptors.response.use(
  (res: AxiosResponse<any>) => {
    console.log(res, "Res");
    const { code } = res.data;
    if (code !== 200) Promise.reject(res.data);
    return res.data.data;
  },
  (err) => Promise.reject(err)
);

export default instance;
